import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { MessageBoardDto } from './dto/message-board.dto';
import { MessageBoardService } from './message-board.service';

@ApiTags('留言板信息管理')
@Controller('message-board')
export class MessageBoardController {
  constructor(private readonly messageBoardService: MessageBoardService) {}

  @ApiOperation({
    summary: '获取留言板信息列表',
  })
  @ApiQuery({
    name: 'limit',
    description: '需要返回的条数',
    example: 200,
  })
  @ApiBearerAuth()
  @Get('/getMessageBoardList')
  getMessageBoardList(@Query('limit') limit = 200) {
    return this.messageBoardService.getMessageBoardList(limit);
  }

  @ApiOperation({
    summary: '增加新留言',
  })
  @ApiBearerAuth()
  @Post('/addMessage')
  addMessage(@Req() req, @Body() messageBoardDto: MessageBoardDto) {
    messageBoardDto.userId = req.user.id;
    return this.messageBoardService.addMessage(messageBoardDto);
  }
}
